package com.restaurant.springboot.entity;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "coupon", schema = "restaurant", catalog = "")
@IdClass(CouponEntityPK.class)
public class CouponEntity {

    private int userId;
    private int couponSeriesId;
    //领取时间
    private Timestamp receiveTime;
    //优惠券是否使用过
    private boolean used;

    public CouponEntity(){

    }

    public CouponEntity(int userId, int couponSeriesId, Timestamp receiveTime, boolean used) {
        this.userId = userId;
        this.couponSeriesId = couponSeriesId;
        this.receiveTime = receiveTime;
        this.used = used;
    }

    @Id
    @Column(name = "user_id")
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Id
    @Column(name = "coupon_series_id")
    public int getCouponSeriesId() {
        return couponSeriesId;
    }

    public void setCouponSeriesId(int couponSeriesId) {
        this.couponSeriesId = couponSeriesId;
    }

    @Basic
    @Column(name = "used")
    public boolean isUsed() {
        return used;
    }

    public void setUsed(boolean used) {
        this.used = used;
    }

    @Basic
    @Column(name = "receive_time")
    public Timestamp getReceiveTime() {
        return receiveTime;
    }

    public void setReceiveTime(Timestamp receiveTime) {
        this.receiveTime = receiveTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CouponEntity that = (CouponEntity) o;
        return userId == that.userId &&
                couponSeriesId == that.couponSeriesId &&
                used == that.used &&
                receiveTime.equals(that.receiveTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userId, couponSeriesId, receiveTime, used);
    }
}
